import java.util.Scanner;

public class Day25 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextLine()) { // 注意 while 处理多个 case
            String n = in.nextLine();
            // 1. 循环判断是否是树根
            while (n.length() > 1) {
                int sum = 0;
                for (int i = 0; i < n.length(); i ++) {
                    sum += (n.charAt(i) - '0');
                }
                n = String.valueOf(sum);
            }
            System.out.println(n);
        }
    }

    public static void main1(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextInt()) { // 注意 while 处理多个 case
            int n = in.nextInt();
            for (int i = 0; i < n; i ++) {
                // 计算斐波那契
                System.out.printf("%04d",getFib(in.nextInt()));
            }
            System.out.println();

        }
    }
    private static long getFib(int n) {
        if (n == 1) {
            return 1;
        }
        int a = 1;
        int b = 2;
        while (n > 2) {
            int tmp = b;
            // 防止越界
            b = (a + b) % 10000;
            a = tmp;
            n --;
        }
        return b;
    }
}
